package com.osgi.desktop.ui.plugins.model;

import com.osgi.desktop.domain.SitePlugin;
import com.osgi.desktop.domain.SiteUpdate;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;

public class DisponiveisPluginsTreeTableModel extends DefaultTreeTableModel {
    
    private String[] colunas = {"Fornecedor","Plugins Disponíveis"};
       
    public DisponiveisPluginsTreeTableModel(DefaultMutableTreeTableNode root)   
    {   
        super(root);
    }   
       
    @Override
    public int getColumnCount()    
    {   
        return colunas.length;   
    }   
       
    @Override  
    public String getColumnName(int col)   
    {   
        return colunas[col];   
    }     
  
    @Override
    public boolean isCellEditable(Object node, int column)    
    {   
         return false;   
    }   
               
    @Override
    public Object getValueAt(Object node, int columnIndex)    
    {      
        Object value = null;
        DefaultMutableTreeTableNode defaultMutableTreeTableNode = (DefaultMutableTreeTableNode)node;
        Object userObject = defaultMutableTreeTableNode.getUserObject();
        if (userObject != null) {            
            if (userObject instanceof SiteUpdate) value = getSiteUpdate((SiteUpdate)userObject, columnIndex);
            else if (userObject instanceof SitePlugin) value = getSitePlugin((SitePlugin)userObject, columnIndex);
        }            
        return value;   
    }
    
    private Object getSiteUpdate(SiteUpdate siteUpdate, int columnIndex){
        Object value = null;
        switch(columnIndex){
            case 0:                                
                value = siteUpdate.getNome();
                break;            
        }        
        return value;
    }
    
    private Object getSitePlugin(SitePlugin sitePlugin, int columnIndex) {
        Object value = null;
        switch(columnIndex){
            case 1:                                
                value = sitePlugin.getNome();
                break;            
        }        
        return value;
    }
}
